package com.sz.main;

import android.app.Application;
import android.content.Intent;
import android.widget.Toast;

import cn.com.geartech.gcordsdk.GcordSDK;
import cn.com.geartech.gcordsdk.HomeKeyManager;
import cn.com.geartech.gcordsdk.PhoneAPI;

/**
 * Created by pangyuning on 15/11/11.
 */
public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();


        GcordSDK.getInstance().initSDK(this, "472586796@qq.com", "29a0d98b-cd02-4ff3-b2b0-85b7d1588a61");

        GcordSDK.getInstance().getPhoneAPI().addPhoneEventListener(phoneEventListener);

        //GcordSDK.getInstance().getHomeKeyManager().setHomeKeyActionType(HomeKeyManager.HOME_KEY_ACTION_TYPE.NONE);

        //GcordSDK.getInstance().getHomeKeyManager().setHomeKeyActionType(HomeKeyManager.HOME_KEY_ACTION_TYPE.PICK_UP);

        GcordSDK.getInstance().getHomeKeyManager().setHomeKeyActionType(HomeKeyManager.HOME_KEY_ACTION_TYPE.CUSTOM_KEY_EVENT);

//        GcordSDK.getInstance().getHomeKeyManager().addHomeKeyEventListener(homeKeyListener);

        GcordSDK.getInstance().getPrinterManager().enablePrinterService();
    }

//    HomeKeyManager.HomeKeyListener homeKeyListener = new HomeKeyManager.HomeKeyListener() {
//        @Override
//        public void onHomeClicked() {
//            Toast.makeText(App.this, "custom home key clicked", Toast.LENGTH_SHORT).show();
//        }
//    };

    @Override
    public void onTerminate() {
        super.onTerminate();

        GcordSDK.getInstance().getPhoneAPI().removePhoneEventListener(phoneEventListener);
//        GcordSDK.getInstance().getHomeKeyManager().removeHomeKeyEventListener(homeKeyListener);

    }


    PhoneAPI.PhoneEventListener phoneEventListener = new PhoneAPI.PhoneEventListener() {
        @Override
        public void onPickUp(PhoneAPI.PICKUP_STATE pickup_state) {

        }

        @Override
        public void onInComingCall() {

            Intent intent = new Intent(getApplicationContext(), InCallActivity.class);
            intent.putExtra(InCallActivity.CALL_TYPE, InCallActivity.CALL_TYPE_IN);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(intent);

        }

        @Override
        public void onRingEnd() {

        }

        @Override
        public void onPhoneNumberReceived(String s) {

        }

        @Override
        public void onSwitchPhoneState(PhoneAPI.PICKUP_STATE pickup_state) {

        }

        @Override
        public void onHangOff() {

        }
    };
}
